package com.wksc.framework.impexp.handler.exp;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.List;

import com.wksc.framework.impexp.constants.PostfixType;
import com.wksc.framework.impexp.template.ExpTemplate;
import jxl.read.biff.BiffException;
import jxl.write.WriteException;

/**
 * <p> Title(文件名): ExpClassicHandler.java </p>
 * <p> Description(描述): 导出任务的传统模式处理类 </p>
 * <p> Copyright(版权): Copyright (c) 2011 </p>
 * <p> Company(公司): 成都四方信息技术有限公司 </p>
 * <p> CreateTime(生成日期)：2011-11-23 下午06:01:45 </p>
 * @author wanglei
 * @version impExp
 */
public class ExpClassicHandler extends BaseExpHandler {
	private static final long serialVersionUID = 3553080698393595240L;
	private BaseExpHandler expHandler;

	public ExpClassicHandler(ExpTemplate expTemplate) throws BiffException, FileNotFoundException, IOException {
		super(expTemplate);
	}
	
	@Override
	public BaseExpHandler getHandlerInstance() throws BiffException, FileNotFoundException, IOException {
		if (isMultiFile) {
			expHandler = new ExpCsvHandler(expTemplate); // 若导出多个文件则交由Csv模式来处理
		} else {
			expHandler = new ExpXlsHandler(expTemplate); // 若导出为单个文件则交由Xls模式来处理
		}
		expHandler.isMultiFile = isMultiFile;
		return expHandler;
	}

	@Override
	public int writeToFile(List<?> data) throws IOException, WriteException,
			BiffException {
		return expHandler.writeToFile(data);
	}

	@Override
	protected void init() throws BiffException, FileNotFoundException,
			IOException {
	}

	@Override
	public PostfixType getPostfix() {
		if (isMultiFile) {
			return PostfixType.CSV;
		} else {
			return PostfixType.XLS;
		}
	}
}
